package com.tgy.algorithm.base;

public class _查找当前元素最右的元素 {

    public static int findMaxRight(int[] nums,int val) {

        if (nums == null || nums.length == 0){
            return -1;
        }

        int maxRight = -1;

        int left = 0;
        int right = nums.length - 1;

        while (left <= right){
            int mid = left + (right - left) / 2;
            if(nums[mid] > val){
                right = mid -  1;
                maxRight = mid;
            }else if(nums[mid] == val){
                left = mid + 1;
                maxRight = mid;
            } else{
                left = mid + 1;
            }
        }

        return maxRight;
    }

    public static void main(String[] args) {
        // num > num[i]

        // 2,2,3,3,4,6        3/2/5/7
        int[] nums = {2,2,3,3,4,6};
        int maxRight = findMaxRight(nums, 2);
        System.out.println(maxRight);
    }
}
